package view.WelcomePanels.SubPanels.MainButtonPanels;

import domain.WelcomeController;
import dto.RegisterDTO;
import dto.WelcomeDTO;
import java.awt.event.ActionEvent;
import java.net.ConnectException;
import javax.swing.JOptionPane;

/**
 *
 * @author Joachim
 */
public class RegisterButtonPanel extends MainButtonPanel {
    
    public RegisterButtonPanel(WelcomeDTO dto, WelcomeController controller) {
        super(dto, controller, "Register");
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        try {
            boolean registerSuccess = super.controller.register((RegisterDTO)super.dto);
            if(registerSuccess) {
                JOptionPane.showMessageDialog(null, "Registration successful, you can now log in.");
            }
            else {
                JOptionPane.showMessageDialog(null, "Registration failed.");
            }
        }
        catch(IllegalArgumentException iae) {
            JOptionPane.showMessageDialog(null, iae.getMessage());
        }
        catch(ConnectException ce) {
            JOptionPane.showMessageDialog(null, ce.getMessage());
        }
    }
    
}
